package com.xyazm.risk.api;

import com.xyazm.common.core.JsonResult;
import com.xyazm.risk.domain.dto.CheckOrderRiskDTO;
import com.xyazm.risk.domain.param.CheckOrderRiskParam;
import com.xyazm.risk.exception.RiskBizException;
import com.xyazm.risk.service.IRiskService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 风控服务对外暴露的接口实现类
 * @author xuyou
 * 2022/8/3 0003 19:17
*/
@Slf4j
@DubboService(version = "1.0.0",interfaceClass = IRiskApi.class)
public class RiskApi implements IRiskApi {

    @Autowired
    private IRiskService riskService;

    @Override
    public JsonResult<CheckOrderRiskDTO> checkOrderRisk(CheckOrderRiskParam param) {
        try {
            CheckOrderRiskDTO checkOrderRiskDTO = riskService.checkOrderRisk(param);
            return JsonResult.buildSuccess(checkOrderRiskDTO);
        } catch (RiskBizException e) {
            log.error("biz error", e);
            return JsonResult.buildError(e.getErrorCode(), e.getErrorMsg());
        } catch(Exception e) {
            log.error("system error", e);
            return JsonResult.buildError(e.getMessage());
        }
    }
}
